# -*- python -*-
# ex: set syntax=python:

# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import config
import master_site_config

from buildbot.scheduler import Scheduler
from master import gitiles_poller
from master import master_utils
from master import slaves_list
from master.factory import annotator_factory


ActiveMaster = master_site_config.Boringssl

MAIL_NOTIFIER = ActiveMaster.is_production_host


# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)
c['slavePortnum'] = ActiveMaster.slave_port


####### DATABASE

config.DatabaseSetup(c, require_dbconfig=ActiveMaster.is_production_host)


####### CHANGESOURCES

poller = gitiles_poller.GitilesPoller(
    'https://boringssl.googlesource.com/boringssl/',
    pollInterval = 60)

c['change_source'] = [poller]

####### FACTORIES

f_common = annotator_factory.AnnotatorFactory().BaseFactory(recipe='boringssl')


####### BUILDERS

builders = [
    {'name': 'linux'},
    {'name': 'linux_shared'},
    {'name': 'linux32'},
    {'name': 'linux_noasm_asan'},
    {'name': 'win64'},
    {'name': 'win32'},
    {'name': 'mac'},
]

for builder in builders:
  builder['builddir'] = builder['name']
  builder['factory'] = f_common
  builder.setdefault('auto_reboot', False)

c['builders'] = builders


####### SCHEDULERS

c['schedulers'] = [
    Scheduler(
        name='boringssl',
        branch='master',
        treeStableTimer=60,
        builderNames=[builder['name'] for builder in c['builders']]
    )
]


###### SLAVES

# Associate the slaves to the manual builders. The configuration is in
# slaves.cfg.
slaves = slaves_list.SlavesList('slaves.cfg', 'Boringssl')
for builder in c['builders']:
  builder['slavenames'] = slaves.GetSlavesName(builder=builder['name'])

c['slaves'] = master_utils.AutoSetupSlaves(c['builders'],
                                           config.Master.GetBotPassword())


###### STATUS TARGETS

# Must come before AutoSetupMaster().
c['buildbotURL'] = ActiveMaster.buildbot_url

master_utils.AutoSetupMaster(
    c, ActiveMaster, mail_notifier=MAIL_NOTIFIER,
    order_console_by_time=True,
    public_html='../master.chromium/public_html',
    templates=['../master.chromium/templates',
               '../master.chromium/templates'])


###### PROJECT IDENTITY

c['projectName'] = ActiveMaster.project_name
c['projectURL'] = ActiveMaster.project_url
